package com.kx.game.center.serverDistribution;

import com.alibaba.fastjson.JSONObject;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

public interface ServerDistributionInterface {

    JSONObject execute(HttpServletRequest request, HttpServletResponse response)throws Exception;

    enum ServerDistributionEnum{

        NEARBY(1, "就近分配", new NearbyDistribution()),

        EQUILIBRIUM(2, "均衡分配", new EquilibriumDistribution()),

        MANUAL(3, "手动分配", new ManualDistribution());

        private int index;

        private String value;

        private ServerDistributionInterface serverDistributionInterface;

        ServerDistributionEnum(int index, String value, ServerDistributionInterface serverDistributionInterface) {
            this.index = index;
            this.value = value;
            this.serverDistributionInterface = serverDistributionInterface;
        }

        public static ServerDistributionInterface getByIndex(int index) {
            for (ServerDistributionEnum serverDistributionEnum : ServerDistributionEnum.values()) {
                if (serverDistributionEnum.index == index)
                    return serverDistributionEnum.serverDistributionInterface;
            }
            return null;
        }
    }
}
